<template>
  <view class="container">
	  <!-- <z-nav-bar></z-nav-bar> -->
	  <z-nav-bar backState='1000' type='transparent' :titleCenter='true' title=''></z-nav-bar>
	  <!-- 公共组件-每个页面必须引入 -->
	  <public-module></public-module>
    <!-- <image class="bg-image" src="@/static/dati/login.png" mode="widthFix"></image> -->
    <view class="content">
      <input class="input-box" placeholder="请输入口令" v-model="obj.code"></input>
      <button class="login-btn" @click="$noMultipleClicks(submit(),1000)">开始答题</button>
    </view>
  </view>
</template>

<script>
import $http from '@/config/requestConfig'
import store from '@/store';
export default {
	data() {
		return {
			obj:{
				code:"",
				name:"",
				unit:""
			}
		};
	},
	//第一次加载
	onLoad(opt) {
		this.obj.name = opt.name
		this.obj.unit = opt.unit
		// 隐藏原生的tabbar
		uni.hideTabBar();
	},
	//页面显示
	onShow() {
		// $http.post('api/open/v1/login', {}).then(res => {
		// 		loginStart = true;
		// 		store.commit('setUserInfo', res);
		// 		callback && callback();
		// 		if (res.nullUserInfo) {
		// 			// 没有绑定过微信的头像或者昵称弹出授权获取头像昵称的弹窗
		// 		} else {
		// 			uni.showToast({
		// 				title: "登录成功"
		// 			});
		// 		}
		// 	}, err => {
		// 		loginStart = true;
		// 	});
		// 隐藏原生的tabbar
		uni.hideTabBar();
	},
	//方法
	methods: {
		submit(){
			let that = this
			if(!this.obj.code){
				uni.showToast({
					title:'请输入口令',
					icon: "none"
				});
				return
			}
			store.commit("setLoadingShow", true);
			uni.request({
			  url: 'http://124.222.44.60:9090/jeecg-boot/h5/api/examQuestionBank/login',
			  method: 'POST',
			  header: {
			    'Content-Type': 'application/x-www-form-urlencoded'
			  },
			  data: this.obj,
			  success: (res) => {
				  if(res.data.code==200){
					  if(res.data.result){
						  that.getKS(res.data.result.id)
						  uni.setStorageSync('tmData', JSON.stringify(res.data.result));
						  uni.removeStorageSync('quizProgress')
						  uni.navigateTo({
						  	url:`/pages/dati/tm`
						  })
					  }else{
						  uni.showToast({
						  	title:'你输入的口令没有录入题目',
						  	icon: "none"
						  });
					  }
					  
				  }else{
					  console.log(res.data.message,"res.message")
					  uni.showToast({
					  	title: res.data.message,
					  	icon: "none"
					  });
				  }
				  store.commit("setLoadingShow", false);
			    console.log('请求成功:', res.data);
			  },
			  fail: (err) => {
				  uni.showToast({
				  	title: err,
				  	icon: "none"
				  });
				  store.commit("setLoadingShow", false);
			    console.error('请求失败:', err);
			  }
			});
			
		},
		//记录考试人数
		getKS(ids){
			let obj = {
				id:ids,
				type:1
			}
			uni.request({
			  url: 'http://124.222.44.60:9090/jeecg-boot/h5/api/examQuestionBank/submitRecordsLog',
			  method: 'GET',
			  // header: {
			  //   'Content-Type': 'application/x-www-form-urlencoded'
			  // },
			  data:obj,
			  success: (res) => {
				  if(res.data.code==200){
					  }
			  },
			  fail: (err) => {
				  uni.showToast({
				  	title: err,
				  	icon: "none"
				  });
				  store.commit("setLoadingShow", false);
			    console.error('请求失败:', err);
			  }
			});
		},
	},
	//页面隐藏
	onHide() {},
	//页面卸载
	onUnload() {},
	//页面下来刷新
	onPullDownRefresh() {},
	//页面上拉触底
	onReachBottom() {},
	//用户点击分享
	onShareAppMessage(e) {
		
	}
};
</script>

<style scoped>
.uni-input-placeholder{
	color: #646464;
	letter-spacing: 1px;
	font-size: 17px;
	font-weight: 500;
}
.container {
	background-image: url('../../static/dati/login.png');
	background-position: center; /* 图片居中 */  
	  background-repeat: no-repeat; /* 不重复 */  
	  background-size: cover; /* 覆盖整个元素，保持宽高比 */  
	  background-attachment: fixed; /* 可选，使背景图在滚动时不滚动 */
	  height: 100vh;
  position: relative;
  width: 100%;
  /* height: 100vh; */
  display: flex;
  justify-content: center;
  align-items: center;
}

.bg-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover; /* Ensures the image fills the entire background */
  z-index: -1;
}

.content {
  width: 90%;
  text-align: center;
}

.welcome-text {
  font-size: 24px;
  color: #333;
  margin-bottom: 20px;
}

.input-box {
  width: 100%;
  height: 50px;
  border-radius: 25px;
  margin-bottom: 20px;
  padding: 0 10px;
  background: transparent;
  border: 1px solid  rgba(0, 0, 0, 0.1);
  color:#000;
  /* box-shadow: 2px 2px 2px 2px rgba(0, 0, 0, 0.1); */
}

.login-btn {
  width: 100%;
  height: 50px;
  background: linear-gradient(to right, #38b448, #1c8c55);
  border-radius: 25px;
  color: white;
  font-size: 18px;
  line-height: 50px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
</style>